<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<title>OS3 Grid Example 3 - Selectable Cells Grid</title>
	<link type="text/css" rel="stylesheet" href="css/examples.css" />
	<link type="text/css" rel="stylesheet" href="../os3grid.css" />
	<script src="../../../os3jslib/liwe.js" type="text/javascript"></script>
	<script src="../os3grid.js" type="text/javascript"></script>
	


</head>
<body>
<div id="block_top">
	<h2 class="center">OS3Grid Example 3 - Selectable Cells Grid</h2>
	<h4 class="center">By Fabio Rotondo - fsoft (@) sourceforge ( dot ) net</h4>
</div>

<div id="block_left">
	<div class="menu_title">Examples</div>

	<div>
		<a href="index.html">Main Page</a><br />
		<a href="ex1.html">Simple Grid</a><br />
		<a href="ex2.html">Sortable Grid</a><br />
		<a href="ex3.html">Selectable Cells Grid</a><br />
		<a href="ex4.html">Editable Grid</a><br />
		<a href="ex5.html">Custom Callbacks</a><br />
		<a href="ex6.html">Rows Selection</a><br />
		<a href="ex7.html">Column Resize</a><br />
		<a href="ex8.html">Column Renderers</a><br />
		<a href="ex9.html">Delete row</a><br />
	</div>
	<div class="menu_title">Advanced Examples</div>
	<div>
		<a href="adv_styles.html">Setting and Using Styles</a><br />
		<a href="adv_edit.html">Using OS3Grid to edit a dataset</a><br />
		<a href="adv_cell_manip.html">Advanced Cell Value Manipulation</a><br />
	</div>

	<div class="menu_title">Support OS3Grid</div>
	<a href="http://sourceforge.net/donate/index.php?group_id=132180" target="_blank"><img src="http://images.sourceforge.net/images/project-support.jpg" width="88" height="32" border="0" alt="Support OS3Grid" /> </a>
</div>

<div id="block_middle">
	<div>
		Now that you have learned all the basics from <a href="ex1.html">Example 1</a>, it is just time to give our grid a bit
		of life.<br />
		One of the advantages of having a grid on the webpage (from a user point of view) is that you can sort the rows by clicking
		on the column names. Let's see how to achieve this with OS3Grid. <br />
		In the code presented in <a href="ex1.html">Example 1</a> add the following line of code before the <tt>g.render()</tt>
		instruction:

		<div class="code"><pre>
			g.set_sortable ( true );
		</pre></div>

		Yeah, you name it! Just a single line of code and you have sortable rows!<br />

		But let's get a bit further... What I really like on grids is the ability to have a single row
		highlighted when I move the mouse, so I can immediately have a glimpse of all row data at the same time.
		This is another one-liner for OS3Grid. Just put this right after (or before :-) &nbsp;the <tt>g.set_sortable()</tt>

		<div class="code"><pre>
			g.set_highlight ( true );
		</pre></div>
 
		That's all! The result should be quite similar with the following:
		<div class="result">

			<div id="grid"></div>
			<script type="text/javascript">
				function cell_clicked ( grid, cell, row_num, col_num, val )
				{
					alert ( "Grid: " + grid.id + " cell: " + cell + " - rown: " + row_num + " - col: " + col_num + " - val: " + val );

					return ( true );
				}

				// Create an OS3Grid instance
				var g = new OS3Grid ();

				// Grid Headers are the grid column names
				g.set_headers ( 'nick', 'Name', 'Surname', 'E-Mail Address' );

				// Now, we add some rows to the grid
				g.add_row ( 'fsoft', 'Fabio', 'Rotondo', 'fsoft (@) sourceforge (dot) net' );
				g.add_row ( 'john', 'John', 'Bustone', 'jbust (@) somewhere (dot) net' );
				g.add_row ( 'mkey', 'Mark', 'Key', 'mkey (@) okay (dot) net' );
				g.add_row ( 'jdoe', 'John', 'Doe', 'redbull (@) batman (dot) net' );

				// Enable sortable rows
				g.sortable = true;

				// Enable highlight of rows with the mouse
				g.highlight = true;

				g.set_cell_click ( cell_clicked );

				// Show the grid replacing the original HTML object with the "grid" ID.
				g.render ( 'grid' );
			</script>

		</div>
	</div>
</div>

</body>
</html>

